import { request } from '../request';
import { ShelfMethods, UpperParams } from './interface';

/**
 * @desc 上架的内容是什么 1 课件包 2 计划模版 3 课程 4 试卷
 */
class Shelf implements ShelfMethods {
  private type: number;

  constructor(type: number) {
    this.type = type;
  }

  static UPPERURL = '/safe/api/shelves/upper';
  static DOWNUrl = '/safe/api/shelves/down';

  /**
   * @desc 上架静态方法
   */
  static async upper(type: number, params: Partial<UpperParams>) {
    try {
      await request({
        url: Shelf.UPPERURL,
        data: {
          type,
          ...params,
        },
      });
      return true;
    } catch (e) {
      return false;
    }
  }
  /**
   * @desc 下架静态方法
   */
  static async down(type: number, guid: string) {
    // try {
    const { data, msg } = await request({
      url: Shelf.DOWNUrl,
      params: {
        type,
        guid,
      },
    });
    return { data: data, msg: msg };
    // } catch (e) {
    //   return false;
    // }
  }

  upper(params: Partial<UpperParams>) {
    return Shelf.upper(this.type, params);
  }

  down(guid: string) {
    return Shelf.down(this.type, guid);
  }
}

export default Shelf;
